import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { SupplierVO, SupplierForm, SupplierQuery } from '@/api/goods/supplier/types';

/**
 * 查询供应商列表
 * @param query
 * @returns {*}
 */

export const listSupplier = (query?: SupplierQuery): AxiosPromise<SupplierVO[]> => {
  return request({
    url: '/order/supplier/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询供应商详细
 * @param id
 */
export const getSupplier = (id: string | number): AxiosPromise<SupplierVO> => {
  return request({
    url: '/order/supplier/' + id,
    method: 'get'
  });
};
/**
 * 生成客户/供应商编号
 * @param id
 */
export const getAutoItemNo = (): AxiosPromise<SupplierVO> => {
  return request({
    url: '/order/supplier/getAutoItemNo',
    method: 'get'
  });
};
/**
 * 校验客户/供应商编号是否存在
 * @param id
 */
export const checkAutoItemNo = (data: any): AxiosPromise<SupplierVO> => {
  return request({
    url: '/order/supplier/checkAutoItemNo',
    method: 'post',
    data: data
  });
};

/**
 * 查询供应商详细
 */
export const getSupplierAllList = (obj: any): AxiosPromise<SupplierVO> => {
  return request({
    url: '/order/supplier/allList',
    method: 'get',
    params: obj
  });
};

/**
 * 新增供应商
 * @param data
 */
export const addSupplier = (data: SupplierForm) => {
  return request({
    url: '/order/supplier',
    method: 'post',
    data: data
  });
};

/**
 * 修改供应商
 * @param data
 */
export const updateSupplier = (data: SupplierForm) => {
  return request({
    url: '/order/supplier',
    method: 'put',
    data: data
  });
};

/**
 * 删除供应商
 * @param id
 */
export const delSupplier = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/supplier/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param supplierId 客户端id
 * @param status 状态
 */
export function changeStatus(supplierId: string, status: string) {
  const data = {
    supplierId,
    status
  };
  return request({
    url: '/order/supplier/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list: listSupplier,
  get: getSupplier,
  add: addSupplier,
  update: updateSupplier,
  del: delSupplier,
  getSupplierAllList: getSupplierAllList,
  getAutoItemNo: getAutoItemNo,
  checkAutoItemNo: checkAutoItemNo,
}